package com.ebupt.migu.music.autoTri.util;

import com.ebupt.migu.music.autoTri.Mapper.AutoTouchOffMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @author xuhongsong
 * @version 1.0
 * @date 2020/8/12 15:42
 */
@Component
public class MethodService {


    public static MethodService methodService;
    @Autowired
    private AutoTouchOffMapper autoTouchOffMapper;

    @PostConstruct
    public void init() {
        methodService = this;
        this.autoTouchOffMapper = autoTouchOffMapper;
    }

    /**
     * 如果允许  就返回true
     *
     * @return
     */
    public Boolean anotherMethod(int afterStatus, int currentStatus) {
        //获取调用者的类名
        String className = new Exception().getStackTrace()[1].getClassName();
        //获取调用者的方法名
        String methodName = new Exception().getStackTrace()[1].getMethodName();
        Map<String, Object> map = new HashMap<>();
        map.put("className", className);
        map.put("methodName", methodName);
        map.put("afterStatus", afterStatus);
        map.put("currentStatus", currentStatus);
        int status = autoTouchOffMapper.executeStatus(map);
        if (status == 1) {
            return true;
        }
        return false;
    }


}
